import type {
  UserRoleAddDTOType,
  UserRoleUpdateDTOType,
  UserRoleSearchDTOType,
} from '@/resources/interface/userRole/UserRoleTypes'
import type { ResultTypes } from '@/resources/interface/ResultTypes'
import { HttpResultUtil } from '@/apis/utils/HttpResultUtil'

export class UserRoleApi {
  private static addUrl: string = '/userRole/add'
  private static updateUrl: string = '/userRole/update'
  private static searchUrl: string = '/userRole/search'
  private static deleteUrl: string = '/userRole/delete'
  private static findRoleUrl: string = '/userRole/find/role'

  static findRole(data: number): Promise<ResultTypes> {
    return HttpResultUtil.awaitGet(this.findRoleUrl, { roleId: data }, false)
  }

  static add(data: UserRoleAddDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.addUrl, data, true)
  }

  static update(data: UserRoleUpdateDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.updateUrl, data, true)
  }

  static search(data: UserRoleSearchDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.searchUrl, data, false)
  }

  static delete(idList: Array<number>): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.deleteUrl, idList, true)
  }
}
